Flag type option (boolean type, no explicit value) for CLI#31
Flag type option (boolean type, no explicit value) for CLI#31NekoiNemo wants to merge 1 commit intonpryce:masterfrom NekoiNemo:cli-flag-option
Conversation
|
👍 I really would love to see this merged @npryce |
|
|
||
| properties[configNameByOpt.configNameFor(opt)] = CommandLineProperty(arg, args[i]) | ||
| if (i + 1 >= args.size || args[i+1].startsWith("-")) { | ||
| properties[configNameByOpt.configNameFor(opt)] = CommandLineProperty(arg, "true") |
There was a problem hiding this comment.
I think this would be confusing for non-boolean options. Is there a way to make this type-safe and work for booleans only?
There was a problem hiding this comment.
Or, generalise it and make it work for any type? That way, it could work for enums as well as booleans.
For example: the CommandLineProperty class could have an optional (nullable) default value field. If it is non-null, that value is used when an explicit argument is not given.
An overload of the CommandLineProperty function for boolean keys could set the default value to true.
There was a problem hiding this comment.
I thought about providing a PR on my own for this and my solution would have been to introduce a CommandLineFlag class that is meant for exactly that. However, by now I think that the best solution would be to interpret every booleanType as a flag since nothing else makes sense.
I would like to suggest adding flag type CLI argument support (that is set to true by its mere inclusion).
Similar to --help/-h